package com.qishenyuan.competition.controller;

import com.qishenyuan.competition.annotation.TokenParam;
import com.qishenyuan.competition.common.Response;
import com.qishenyuan.competition.dto.CreateTopicReq;
import com.qishenyuan.competition.service.OssService;
import com.qishenyuan.competition.service.TeamupService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * @author qishenyuan
 * @since 2025-03-02
 */
@RestController
@RequestMapping("/topic")
public class TopicController {

    @Resource
    private OssService ossService;

    @Resource
    private TeamupService teamupService;

    @RequestMapping("/uploadImages")
    public Response<Map<String, List<String>>> upload(@RequestParam("files") MultipartFile[] files) {
        return Response.ok(ossService.upload(files));
    }

    @RequestMapping("/deleteImages")
    public Response<?> deleteImages(@RequestParam String objectName) {
        ossService.deleteFile(objectName);
        return Response.ok();
    }

    @RequestMapping("/createTopic")
    public Response<?> createTopic(@TokenParam String token, @RequestBody @Validated CreateTopicReq createTopicReq) {
        teamupService.createTopic(token,createTopicReq);
        return Response.ok();
    }
}

